#!/bin/bash

workingDir=$1
if [ "$workingDir" == '' ]
then
    workingDir='/cmsdata/cf/cf_program'
fi

echo '[info] inverting user id hashmap...'
awk -F': '  'BEGIN {print "---"} {if($1!=nil && $1!="---" && $1!="--- ") {print $2 ": " $1}}' /$workingDir/yaml/userIdMap > /$workingDir/yaml/userIdMap_invert_tmp

echo '[info] eliminating " symbol... '
sed 's/"//g' /$workingDir/yaml/userIdMap_invert_tmp > /$workingDir/yaml/userIdMap_invert

echo '[info] removing temp file...'
rm -f /$workingDir/yaml/userIdMap_invert_tmp

echo '[info] inverting program id hashmap...'
awk -F': '  'BEGIN {print "---"} {if($1!=nil && $1!="---" && $1!="--- ") {print $2 ": " $1}}' /$workingDir/yaml/programIdMap > /$workingDir/yaml/programIdMap_invert

